{include file='header.html'}
<link type="text/css" href="../../page/css/delay.css" rel="stylesheet">
<link type="text/css" href="{$common_domain}/tools/datepicker/jquery.ui.theme.css" rel="stylesheet" />
<link type="text/css" href="{$common_domain}/tools/datepicker/jquery.ui.datepicker.css" rel="stylesheet" />
<link type="text/css" href="{$common_domain}/tools/datepicker/jquery-ui-1.8.16.custom.css" rel="stylesheet" />
<script type="text/javascript" src="{$common_domain}/tools/datepicker/jquery-1.7.2.js"></script>
<script type="text/javascript" src="{$common_domain}/tools/datepicker/jquery.ui.core.js"></script>
<script type="text/javascript" src="{$common_domain}/tools/datepicker/jquery.ui.widget.js"></script>
<script type="text/javascript" src="{$common_domain}/tools/datepicker/jquery.ui.datepicker.js"></script>
<script type="text/javascript" src="{$common_domain}/tools/datepicker/DateTimePicker.js"></script>
<script type="text/javascript">

$(function () {
    var myannual = {$annual.left};
    $("#start_time").datetimepicker();
    $("#end_time").datetimepicker('end_time');
    $("#deli_time").datetimepicker();
    var url = window.location.href;
    $("#needpic").hide();

    $.datetimepicker.after_set = function($this){
       var id = $this.attr("id");

       if( id == 'start_time' || id == 'end_time' ) {
            var start = $("#start_time").val();
            var end = $("#end_time").val();
            var reason = $("#reason").val();
            if( start == '' || end == '' || reason == ''){
                return ;
            }else{
                if(comptime(start,end)){
                    $.post(url,{ start:start,end:end,cal:'long',type:reason},function (data) {
                        if(data.is_ever == 1){
                            $("#days").val(0);
                            $("#"+id).val("");
                            alert("您在"+data.has_days+"已有请假记录,同一时段不能请多次");
                        }else{
                            $("#days").val(data.day);
                            if(data.day > 3) {
                                $("#leveltwo").show();
                            } else {
                                $("#leveltwo").hide();
                            }
                        }
                    },'json');
                }else{
                    $("#"+id).val("");
                }
            }
       }else if(id == 'deli_time' && $("#reason").val()=='婚假'){
           var marriage = $("#deli_time").val();
           $.post(url,{ marriage:marriage,cal:'overdue'},function (data) {
                if(data){
                    $("#tach_text").text('可用10天，请上传结婚证书影印件');
                }else{
                    $("#tach_text").text('领证日期已经超过6个月，不可使用婚假');

                }
                $("#tach").show();
           });
       }
       else{
            return ;
       }

    }

    $("#reason").change( function () {
        {if !$fd_st}
        $("#start_time,#end_time,#deli_time").val('');
        $("#days").val(0);
        {/if}
        var reason = $("#reason").val();
        if(reason == '事假'){
            $("#tach,#delivery_time,#relation,#needpic").hide();
        }else if(reason == '病假'){
            $("#delivery_time,#relation").hide();
            $("#tach_text").text('请一周内上传区级以上病假证明，若无法提供将视为事假处理');
            $("#tach,#needpic").show();
        }else if(reason == '年假'){
            $("#delivery_time,#relation,#needpic").hide();
            $.post(url,{ cal:'annual'},function (data) {
               if(data == 0){
                $("#tach_text").text('您暂无年假或年假已使用完');
               }else{
                $("#tach_text").text('可用年假'+data+'天');
               }
               $("#tach").show();
            });
        }else if(reason == '产检'){
            $("#delivery_time,#relation").hide();
             $("#tach_text").text('请上传区级以上医院产检凭证或挂号证明');
             $("#tach,#needpic").show();
         }else if(reason == '产前假'){
             $("#relation").hide();
             $("#tach_text").text('妊娠满28周后，若身体不适，可根据医院开具的病假单申请产前假');
             $("#deli_time").attr("placeholder","预产期");
             $("#delivery_time,#tach,#needpic").show();
         }else if(reason == '产假'){
             $("#relation").hide();
             $("#tach_text").text('产假最早可于预产假期前15天开始申请，需上传医院出具的妊娠证明。晚育假遇法定节假日顺延，其他按自然天算，含法定节假日');
             $("#deli_time").attr("placeholder","预产期");
             $("#delivery_time,#tach,#needpic").show();
             $.post(url,{ cal:'chanjia'},function (data) {
                 $("#deli_time").val(data);
              });
         }else if(reason == '丧假'){
             $("#delivery_time,#needpic").hide();
             $("#tach_text").text('可用3天（直系亲属：父母，配偶，亲兄弟姐妹，子女，配偶父母等）');
             $("#relation option:nth-child(1)").attr("selected" , "selected");
             $("#relation,#tach").show();
         }else if(reason == '婚假'){
             $("#relation,#tach").hide();
             $("#tach_text").text('可用10天，请上传结婚证书影印件');
             $("#deli_time").attr("placeholder","结婚证申领日期");
             $("#delivery_time,#needpic").show();
         }else if(reason == '陪产假'){
             $("#relation,#delivery_time").hide();
             $("#tach_text").text('如妻子晚育，可享受陪产假3天');
             $("#tach,#needpic").show();
         }
    });

    $("#relation").change( function () {
        if($(this).val() == '非直系亲属'){
            $("#tach_text").text('可用1天（非直系亲属：爷爷奶奶，外公外婆，表/唐兄弟姐妹等）');
        }else{
            $("#tach_text").text('可用3天（直系亲属：父母，配偶，亲兄弟姐妹，子女，配偶父母等）');
        }
    });


    $("form:first").submit(function(){
        var reason = $("#reason").val();

        if(reason =='婚假'){
            var start = $("#start_time").val();
            var deli = $("#deli_time").val();
            var days = $("#days").val();
            if(start < deli){
                alert('领证后才能请婚假');
                return false;
            }
            if(days >10){
                alert('婚假最多能请10天');
                return false;
            }

        }
        //如果是上传图片使用
        var is_up_file = $('#is_up_file').val();
        if(is_up_file=='1'){
            return true;
        }

        if(confirm("确定提交吗?")){
            var reason = $("#reason").val();
            if(reason == "请选择"){
                alert('请选择原因!');
                return false;
            }
            var day = $("#days").val();
            var start = $("#start_time").val();
            var end = $("#end_time").val();
            start = start.replace(/(-|:| )/g,'');
            end = end.replace(/(-|:| )/g,'');
            if(start >end){
                alert('请正确选取请假起始时间和结束时间');
                return false;
            }
            if(day == 0){
                alert('请正确选取请假起始时间和结束时间');
                return false;
            }
            else if(reason == '年假' && day > myannual){
                alert('年假超过了已有年假，请重新选择时间');
                return false;
            }
            else if(reason == '产检' && day >1){
                alert('产检假不能超过1天');
                return false;
            }
            else if(reason == '陪产假' && day >3){
                alert('陪产假不能超过3天');
                return false;
            }
            else if(reason == '丧假' && day >3){
                alert('丧假不能超过3天');
                return false;
            } else if(reason == '丧假') {
                relation = $("#relation").val();
                if(relation == '非直系亲属' && day > 1) {
                    alert('非直系亲属丧假不能超过1天');
                    return false;
                }
            } else if( (reason == '产前假'|| reason == '产假') && $("#deli_time").val() == ''){
                alert('请输入预产期');
                return false;
            }
            else if( reason == '婚假' && $("#deli_time").val() == ''){
                alert('请输入结婚领证日期');
                return false;
            }else if($("#agent").val() == ''){
                alert('请输入工作代理人');
                return false;
            }
            else{
                return true;
            }
        }
        else{
            return false;
        }
    }
    );
});
function comptime(startDate,endDate) {
    startDate = startDate+":00";
    endDate =endDate+":00";
    if (startDate.length > 0 && endDate.length > 0) {
       var startDateTemp = startDate.split(" ");
       var endDateTemp = endDate.split(" ");

       var arrStartDate = startDateTemp[0].split("-");
       var arrEndDate = endDateTemp[0].split("-");

       var arrStartTime = startDateTemp[1].split(":");
       var arrEndTime = endDateTemp[1].split(":");

       var allStartDate = new Date(arrStartDate[0], parseInt(arrStartDate[1])-1, arrStartDate[2], arrStartTime[0], arrStartTime[1], arrStartTime[2]);
       var allEndDate = new Date(arrEndDate[0], parseInt(arrEndDate[1])-1, arrEndDate[2], arrEndTime[0], arrEndTime[1], arrEndTime[2]);

       if (allStartDate.getTime() >= allEndDate.getTime()) {
          alert("结束时间不能小于开始时间");
          return false;
       } else {
          return true;
       }
   } else {
         return false;
   }
}

var KQUpload = {
    checkFileExt: function(filename){
           var allow_ext = new  Array('.jpg','.jpeg','.gif');
           var ext = filename.substr(filename.lastIndexOf(".")).toLowerCase();
           if(allow_ext.indexOf(ext) != -1){  return true; }
           return false;
        },
    upload_img: function(){
        $("#frmAsk").attr("action", "/ajaxupload/");
        $("#frmAsk").attr("target",'upload_frame');
        $("#frmAsk").submit();
        $("#frmAsk").attr("action", "");
        $("#frmAsk").attr("target",'');
    },
    del_img:function(){
        $('#need_img_li').hide();
        $('#need_img').attr('src','');
        $('#need_img_a').attr('href','');
        $('#img_file').val('');
        $('#is_up_file').val(0);
    }
};
$(document).ready(function(){
    $('#photo_up').change(function(){
        if(!KQUpload.checkFileExt(this.value)){
            alert('您上传的图片类型不符合规则！请重新上传');
            return false;
         }else{
             $('#is_up_file').val(1);
             KQUpload.upload_img();
         }
    });
});
</script>
<div id="content">
    <i class="con_l">&nbsp;</i> <i class="con_r">&nbsp;</i>
    <div class="main">
        <form id="frmAsk" action="" method="post" enctype="multipart/form-data">
        <input type="hidden" name="nj_days" id="nj_days" value="0">
            <ul class="ul_cc">
            <li class="s">
                <b class="li_b">请假类别</b>
                <select name = "type" id = "reason">
                <option value="请选择">请选择</option>
                {foreach from = $leave_types item = type}
                    <option value="{$type}">{$type}</option>
                {/foreach}
                </select>

                <span id = "delivery_time" style="display:none;">
                <input id ="deli_time"  name="delivery_time"  readonly = "readonly" type="text" value="" class ="jko1 jkk" style ="width:150px" />
                </span>

                <select name = "relation" id = "relation" style="display:none">
                    <option value="直系亲属">直系亲属</option>
                    <option value="非直系亲属">非直系亲属</option>
                </select>

                <span class="tach" id = "tach" style="display:none;">
                    <span class="ic"></span>
                    <span id="tach_text"></span>
                    <span class="ico"><a href="/help/" target="_blank" title="查看帮助文档">&nbsp;</a></span>
                </span>
            <li>
            <li class="s">
                <b class="li_b">日期</b>
                <input id = "start_time"  name="start_time" readonly = "readonly" type="text" value="{$fd_st}" class="jko1" style ="width:155px;" />
                至
                <input id = "end_time"   name="end_time" readonly = "readonly" type="text" value="{$fd_et}" class="jko1" style ="width:155px;" />

            <li>

            <li class="s">
                <b class="li_b">天数</b>
                <input name="days" id ="days"  style="width:50px;text-align:center" readonly = "readonly" type="text" value="{if $fd_st}{$fd_days}{else}0{/if}"  /> 天
            <li>

            <li class="s" id="needpic">
                <b class="li_b">图片(文件大小<2M,支持格式jpg/gif)</b>
                <a id="" href="javascript:;" class="tian_one_span">
                  上传证明
                  <input id="photo_up" class="vis2op" type="file" hidefocus="hidefocus" name="file">
                </a>

            <li>
            <li class="s" style="display:none" id="need_img_li">
            <input type="hidden" name="is_up_file" id="is_up_file" value="0">
            <input type="hidden" name="img_file" id="img_file" value="">
            <a href="" target="_blank" id="need_img_a" title="点击查看大图"><img id="need_img" width="240" height="180"></a>&nbsp;<a href="javascript:void(0);" onclick="KQUpload.del_img()" style="margin:0 0 0 10px;">删除</a>
            </li>
            <li class="s">
                <b class="li_b">审批人：{foreach from = $audit_users item = user name = user}{if $smarty.foreach.user.index eq '1'}<span id="leveltwo" style="display:none;">{/if} {$user} {if $smarty.foreach.user.index eq '1'}</span>{/if}{/foreach}</b>
            <li>

            <li class="s">
                <b class="li_b">Note:</b>
                <textarea name = "desc" rows="5" cols="30" maxlength="100" id="tre"></textarea>
            <li>

            <!--工作代理人begin-->
            <li class="s">
                    <b class="li_b">工作代理人</b>
                    <input name="agent" id ="agent"  style="width:270px; height:25px;"  type="text" placeholder="可写多个"/>
            <li>
           <!--工作代理人end-->

            <li class="s"><input type="submit" class="lgo" value="提交申请"></li>
            </ul>

        </form>

    </div>
</div>

<iframe name="upload_frame" id="upload_frame" style="width:0;height:0;display:none;" ></iframe>
{include file='footer.html'}
